package com.cunshe.web.manage;

import com.cunshe.common.ResponseVO;
import com.cunshe.config.annotation.Login;
import com.cunshe.dao.MessageBoardDao;
import com.cunshe.domain.MessageBoard;
import com.cunshe.service.MessageBoardService;
import com.sunkee.entity.page.Pageination;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@Api(tags = "留言板")
@Login
@RestController
@RequestMapping(value = "/manage/messageBoard")
public class MessageBoardController {

    @Autowired
    private MessageBoardService messageBoardService;

    @ApiOperation(value = "新增")
    @PostMapping(value = "insert")
    public ResponseVO insert(MessageBoard record) {
        record.setCreatetime(new Date());
        messageBoardService.insert(record);
        return ResponseVO.success();
    }

    @ApiOperation(value = "删除")
    @PostMapping(value = "delete")
    public ResponseVO delete(Long id) {
        messageBoardService.delete(id);
        return ResponseVO.success();
    }

    @ApiOperation(value = "修改")
    @PostMapping(value = "update")
    public ResponseVO update(MessageBoard record) {
        messageBoardService.update(record);
        return ResponseVO.success();
    }

    @ApiOperation(value = "查询")
    @PostMapping(value = "list")
    public ResponseVO<Pageination<MessageBoard>> list(@RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo, MessageBoard record) {
        Pageination<MessageBoard> pagelist = messageBoardService.pagelist(pageNo, Pageination.DEFAULT_PAGESIZE, record);
        return ResponseVO.success(pagelist);
    }

}